"""
python read_fujian3.py
"""

import pandas as pd
import json
import os

# 文件路径
input_csv_path = '../fujian/fujian3.csv'
output_json_path = '../fujian/fujian3/origin_data/warehouse.json'

# 创建输出目录（如果不存在）
os.makedirs(os.path.dirname(output_json_path), exist_ok=True)

# 读取 CSV 数据
# df = pd.read_csv(input_csv_path)
df = pd.read_csv(input_csv_path, encoding='gbk')  # 如果 'gbk' 不行，可以换成 'ISO-8859-1'


# 重命名列并构造所需格式
warehouse_data = [
    {
        "warehouse_id": row['仓库'],
        "max_inventory": int(row['仓容上限']),
        "max_sales": int(row['产能上限']),
        "daily_cost": float(row['仓租日成本'])
    }
    for _, row in df.iterrows()
]

# 写入 JSON 文件
with open(output_json_path, 'w', encoding='utf-8') as f:
    json.dump(warehouse_data, f, ensure_ascii=False, indent=4)

print("Data has been successfully converted to JSON format and saved.")
